﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.IO;

namespace dahtd4ever
{
    public class Geschoss
    {
        public Rectangle boundarie;

        Vector2 position;
        Vector2 startPosition;
        Vector2 endPosition;

        float moveSpeed;
        Vector2 moveVector;

        Texture2D texture;

        ContentManager contentManager;

        public bool active = true;

        private void Initialize()
        {
            texture = contentManager.Load<Texture2D>("Graphics/blackpx");
        }

        public Geschoss(Vector2 startPos, Vector2 endPos, ContentManager cm)
        {
            this.startPosition = this.position = startPos;
            this.endPosition = endPos;
            boundarie = new Rectangle((int)position.X, (int)position.Y, 10, 10);
            contentManager = cm;
            Initialize();
            // X richtung 
            moveVector = new Vector2();
            moveVector = endPos - startPos;
            moveSpeed = 0.06f;
        }

        public void Update()
        {
            position += moveVector * moveSpeed;
            boundarie.X = (int)position.X;
            boundarie.Y = (int)position.Y;
            if (moveVector.X >= 0 && moveVector.Y >= 0 && (endPosition.X - position.X) <= 0 && (endPosition.Y - position.Y) <= 0) { this.active = false; }
            if (moveVector.X >= 0 && moveVector.Y <= 0 && (endPosition.X - position.X) <= 0 && (endPosition.Y - position.Y) >= 0) { this.active = false; }
            if (moveVector.X <= 0 && moveVector.Y >= 0 && (endPosition.X - position.X) >= 0 && (endPosition.Y - position.Y) <= 0) { this.active = false; }
            if (moveVector.X <= 0 && moveVector.Y <= 0 && (endPosition.X - position.X) >= 0 && (endPosition.Y - position.Y) >= 0) { this.active = false; }
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(texture, boundarie, Color.White);
        }

    }
}
